package bsh.dyn;

import java.util.Arrays;

/**
 * Um callsite eh representado por um id, pelos parametros obtidos e pelo tipo do alvo da invocacao
 * 
 * @author takeshi
 */
public final class Callsite {

    private final int id;

    private final Class<?> receiving;

    private final Class<?>[] params;

    /**
     * C'tor
     * 
     * @param id int
     * @param receiving class
     * @param params class
     */
    public Callsite(int id, Class<?> receiving, Class<?>[] params) {
        super();
        this.id = id;
        this.receiving = receiving;
        this.params = params;
    }

    /**
     * {@inheritDoc}
     * 
     * @see java.lang.Object#hashCode()
     */

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + this.id;
        return result;
    }

    /**
     * {@inheritDoc}
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        Callsite other = (Callsite) obj;
        if (this.id != other.id) {
            return false;
        }
        if (!Arrays.equals(this.params, other.params)) {
            return false;
        }
        if (!this.receiving.equals(other.receiving)) {
            return false;
        }
        return true;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @return the receiving
     */
    public Class<?> getReceiving() {
        return receiving;
    }

    /**
     * @return the params
     */
    public Class<?>[] getParams() {
        return params;
    }

}
